package com.dead.letter.customer;

import com.dead.letter.config.MQConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 死信消费者
 */
@Component
public class DeadCustomer {


    @RabbitListener(queues = MQConfig.DEAD_LETTER_QUEUEA_NAME)
    public void bizCustomerA(Channel channel, Message message){
        System.out.println("-------死信队列A的消费者-------");

        String xx = new String(message.getBody());

        System.out.println("-死信队列A的消费者-获取到的消息：" + xx);

        try {
            //确认消息
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    //进入死信队列
    @RabbitListener(queues = MQConfig.DEAD_LETTER_QUEUEB_NAME)
    public void bizCustomerB(Channel channel, Message message){
        System.out.println("-------死信队列B的消费者-------");

        String xx = new String(message.getBody());

        System.out.println("-死信队列B的取到的消息：" + xx);

        try {
            //确认消息
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
